#pragma once
#include "EngineHead.h"
#include "ResourceBase.h"
#include "Device.h"
namespace mini
{
	enum TextureType
	{
		D1,
		D2,
		D3,
	};

	class CTexture : public CResourceBase
	{
		friend class CRenderToTexture;
		friend class CResourceManager;
	public:
		CTexture();
		virtual ~CTexture();
		virtual bool initialiseShaderResourceView();
		virtual bool initialise() override;
		bool initialiseRenderTexture(INT32 width, INT32 height, UINT32 nFormat);
		void clearRenderTargetView(const CPoint4F& cololr);
		void commitToGpu(DeviceContext* pDeviceContext, INT32 startSlot);
		std::vector<UINT8>	saveAlpha(INT32 x, INT32 y, INT32 width, INT32 height);
		std::vector<UINT8>	saveAlpha();
		TextureType getTextureType();
		void setSampleState(ID3D11SamplerState* pSampleState);
		void setDeviceContext(DeviceContext* pDeviceContext);
		bool isSamplerStateEmpty();

		/*
		typedef enum D3DX11_IMAGE_FILE_FORMAT
		{
			D3DX11_IFF_BMP         = 0,
			D3DX11_IFF_JPG         = 1,
			D3DX11_IFF_PNG         = 3,
			D3DX11_IFF_DDS         = 4,
			D3DX11_IFF_TIFF		  = 10,
			D3DX11_IFF_GIF		  = 11,
			D3DX11_IFF_WMP		  = 12,
			D3DX11_IFF_FORCE_DWORD = 0x7fffffff

			} D3DX11_IMAGE_FILE_FORMAT;
		*/
		bool saveToFile(const std::string saveFile = "", DWORD nFormat = D3DX11_IFF_PNG);
		UINT32 getImageWidth();
		UINT32 getImageHeight();
		UINT32 getFormat() const;
		ID3D11RenderTargetView* getRenderTargetView() const;
		ID3D11ShaderResourceView* getRenderShaderRV() const;
		void copyFrom(ID3D11Texture2D* pTexture, DeviceContext* pContext);

	private:
		TextureType mType = D2;
		DeviceContext* mpDeviceContext = nullptr;
		D3D11_TEXTURE2D_DESC mDesc;
#ifdef WIN32
		ID3D11ShaderResourceView* mpShaderResourceView = nullptr;
		ID3D11Texture2D* mpTexture2D = nullptr;
		ID3D11RenderTargetView* mpRenderTargetView = nullptr;
		ID3D11SamplerState*	m_sampleState = nullptr;
#endif
	};


}
